﻿using CRM.Admin.Contracts.Contract.Customer;
using CRM.Admin.Contracts.Dto.Customer;
using KingsSharp.Common;
using KingsSharp.Common.Extensions;
using KingsSharp.Core.Data.Entity;
using KingsSharp.Web.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CRM.Admin.Areas.Customer.Controllers
{
    /// <summary>
    /// 推广计划
    /// </summary>
    public class PromotionPlanController : Controller
    {
        public IPromotionPlanService PromotionPlanService { get; set; }
        // GET: Customer/PromotionPlan
        public ActionResult PromotionPlanAdd(Guid CustomerId)
        {
            ViewBag.CustomerId = CustomerId;
            return View();
        }
        public ActionResult PromotionPlanEdit(Guid id)
        {
            var data = PromotionPlanService.PromotionPlans.FirstOrDefault(a => a.Id == id).MapTo<PromotionPlanDto>();
            return View(data);
        }
        public ActionResult PromotionPlanDelete(Guid UserId)
        {
            UserId.CheckNotEmpty("UserId");
            Guid[] id = new Guid[] { UserId };
            var result = PromotionPlanService.Delete(id);
            string msg = result.Message ?? result.ResultType.ToDescription();
            AjaxResultType msgType = result.ResultType.ToAjaxResultType();
            if (msgType != AjaxResultType.Error)
            {
                msg = "推广计划删除成功。";
            }
            return Json(new AjaxResult(msg, msgType));
        }

        public ActionResult PromotionPlanInsert(PromotionPlanDto dto)
        {
            dto.CheckNotNull("dto");

            var result = PromotionPlanService.Insert(dto);
            string msg = result.Message ?? result.ResultType.ToDescription();
            AjaxResultType msgType = result.ResultType.ToAjaxResultType();
            if (msgType != AjaxResultType.Error)
            {
                msg = "推广计划添加成功";
            }
            return Json(new AjaxResult(msg, msgType));
        }
        public ActionResult PromotionPlanUpdate(PromotionPlanDto dto)
        {
            dto.CheckNotNull("dto");

            var result = PromotionPlanService.Update(dto);
            string msg = result.Message ?? result.ResultType.ToDescription();
            AjaxResultType msgType = result.ResultType.ToAjaxResultType();
            if (msgType != AjaxResultType.Error)
            {
                msg = "推广计划修改成功";
            }
            return Json(new AjaxResult(msg, msgType));
        }
    }
}